package uk.org.cardboardbox.neodroidpocket;

import java.io.File;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

public class Main extends Activity {
   
	private TextView mFPSCounter;
	private EmuView mEmuView;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.main);
        mFPSCounter = (TextView) this.findViewById(R.id.fpscounter);
        
        
        File romdir = new File("/sdcard/neodroidpocket/");
    	romdir.mkdir();
    	File cartmemdir = new File("/sdcard/neodroidpocket/cartmem/");
    	cartmemdir.mkdir();
        
        NeoGeoPocket.jni_init("/sdcard/neodroidpocket/game.ngc");
        
        NeoGeoPocket mNGP = new NeoGeoPocket();
        
        mEmuView = (EmuView) this.findViewById(R.id.gameview);
        mEmuView.setNGP(mNGP);
        mEmuView.start();
        
        //NeoGeoPocket.jni_cleanup();
        
        new UpdateFrameCounter().run();
    }
    
    private class UpdateFrameCounter implements Runnable {

		@Override
		public void run() {
			mFPSCounter.setText(mEmuView.fps.toString());
			new Handler().postDelayed(new UpdateFrameCounter(), 1000);
		}
    	
    }
}